package com.example.gobang.config;

import com.example.gobang.api.GameAPI;
import com.example.gobang.api.MatchAPI;
import com.example.gobang.api.TestAPI;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;
import org.springframework.web.socket.server.support.HttpSessionHandshakeInterceptor;

/**
 * Created with IntelliJ IDEA.
 * ClassName: WebSocketConfig
 * Package: com.example.gobang.config
 * Description:
 * User: fzykd
 *
 * @Author: LQH
 * Date: 2023-02-23
 * Time: 21:16
 */

@Configuration
@EnableWebSocket //Spring知道这个是配置web的类 这个类找到TestAPI 找到响应的方法
public class WebSocketConfig implements WebSocketConfigurer {
    //这个类 是 将TestAPI注册到Spring框架中


    @Autowired
    private MatchAPI matchAPI;

    @Autowired
    private GameAPI gameAPI;

    //这个方法是 能注册一些类到handle当中
    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry webSocketHandlerRegistry) {
        //将 TestAPI注册到当中
        //关联具体路径 当客户端 关联这具体路径的时候触发当前TestAPI
        webSocketHandlerRegistry.addHandler(new TestAPI(),"/test");

        webSocketHandlerRegistry.addHandler(matchAPI,"/findMatch")
                .addInterceptors(new HttpSessionHandshakeInterceptor());

        webSocketHandlerRegistry.addHandler(gameAPI,"/game")
                .addInterceptors(new HttpSessionHandshakeInterceptor());
    }





}
